package org.adream.account.service;

import java.util.List;

import org.adream.account.dao.AreaDao;
import org.adream.account.entity.AreaEntity;
import org.adream.account.model.ResultModel;
import org.adream.account.util.Constant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 地区service
 * @author sl
 *
 */
@Service
public class AreaService {
	
	private final static Logger logger = LoggerFactory.getLogger(AreaService.class);
	
	@Autowired
	private AreaDao areaDao;
	
	/**
	 * 查询全部Area
	 * @return
	 */
	public List<AreaEntity> queryAreas() {
		return areaDao.queryAreas();
	}
	
	/**
	 * 通过父级id查询Area
	 * @param pid  父级id
	 * @return
	 */
	public List<AreaEntity> queryAreasByPid(Integer pid) {
		return areaDao.queryAreasByPid(pid);
	}
	
	/**
	 * 通过areaId查询Area
	 * @param areaId area id
	 * @return
	 */
	public AreaEntity queryAreaById(Integer areaId) {
		return areaDao.queryAreaById(areaId);
	}
	
	/**
	 * replace地区
	 * @param area
	 * @return
	 */
	public ResultModel<?> replaceArea(AreaEntity area) {
		int result = areaDao.replaceArea(area);
		if(result == Constant.ZERO) {
			logger.warn("replace地区失败,数据库出错:(");
			return new ResultModel<String>(ResultModel.ERR_SYS, "系统出错114,请联系系统管理员", null);
		}
		return new ResultModel<String>(ResultModel.SUCCESS, "操作成功", null);
	}
}